package cn.com.yiqi.wsc.portal.controller.tags;

import cn.com.yiqi.wsc.common.Result;
import cn.com.yiqi.wsc.common.ResultUtil;
import cn.com.yiqi.wsc.dao.tags.criteria.TagCriteria;
import cn.com.yiqi.wsc.dao.tags.entity.TagExample;
import cn.com.yiqi.wsc.portal.controller.BaseController;
import cn.com.yiqi.wsc.service.tag.TagService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author 杨贵森
 * @ClassName:TagController
 * @Title: TagController
 * @Description: TODO
 * @date 2017/3/23
 */
@Controller
@RequestMapping("/tags")
public class TagController extends BaseController {

    @Autowired
    TagService tagService;

    @RequestMapping("/index")
    public ModelAndView index() {
        ModelAndView mv = new ModelAndView("tags/index");
        this.getUserData(mv);
        return mv;
    }

    @RequestMapping(value = "/getTagList")
    @ResponseBody
    public Result getTagList(@RequestBody TagCriteria tagCriteria){

        return tagService.getTagList(tagCriteria);
    }

    @RequestMapping(value = "/addTag")
    @ResponseBody
    public Result addTag(@RequestBody TagExample tagExample){
        Result result = new Result();
        if(tagExample.getType()==null){
            return ResultUtil.paramError(result,"标签类型不能为空");

        }
        if(StringUtils.isEmpty(tagExample.getName())){
            return ResultUtil.paramError(result,"标签名字不能为空");

        }
        return tagService.addTag(tagExample);
    }
    @RequestMapping(value = "/deleteTag")
    @ResponseBody
    public Result deleteTag(@RequestBody TagExample tagExample){

        return tagService.deleteTag(tagExample);
    }
    @RequestMapping(value = "/editTag")
    @ResponseBody
    public Result editTag(@RequestBody TagExample tagExample){
        Result result = new Result();
        if(tagExample.getType()==null){
            return ResultUtil.paramError(result,"标签类型不能为空");

        }
        if(StringUtils.isEmpty(tagExample.getName())){
            return ResultUtil.paramError(result,"标签名字不能为空");

        }
        return tagService.editTag(tagExample);
    }

    @RequestMapping(value = "/selectOneTag")
    @ResponseBody
    public Result getOneTag(@RequestBody TagExample tagExample){

        return tagService.selectOneTagById(tagExample);
    }


}
